package cn.org.xuanguang.kepler.hormos.rdb.dml.warrper;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
 * 通用查询结果包装器大全
 * 该类是工厂分发类，所有的封装器都通过该类分发
 * 例如，想要包装成list格式，则通过如下方式
 * <p>
 * syncSqlExecutor.select(SqlRequests.of("select * from s_user",null), ResultWrappers.mapList());
 * </p>
 *
 * @since 3.0
 */
@NoArgsConstructor(access = AccessLevel.PACKAGE)
public class ResultWrappers<E, R> {
    private ResultWrapper<E, ?> wrapper;

    /**
     * @return map集合结果包装器
     */
    public static ResultWrapper<Map<String, Object>, List<Map<String, Object>>> mapList() {
        System.out.println("ResultWrapperResultWrapper");
        return new MapListWapper();
    }

    /**
     * @return map 单一结果包装器
     */
    public static ResultWrapper<Map<String, Object>, Object> singleMap() {
        return SingleMapMapper.getInstance();
    }

    /**
     * @return object 单一结果包装器
     */
    public static <E, R> ResultWrapper<E, R> singleObject(Class<?> entity) {
        return new SingleObjectMapper(() -> entity);
    }

    /**
     * 结果集转javabean对象，list输出
     *
     * @param entity
     * @return
     */
    public static <E> ResultWrapper<Object, List<E>> toList(Class<E> entity) {
        return new JavaBeanListMapper(singleObject(entity));
    }

}
